package com.android.waterdetection.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.android.waterdetection.R;
import com.android.waterdetection.bean.UserBean;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class UserManagerAdapter extends RecyclerView.Adapter<UserManagerAdapter.ViewHolder> {

    private Context mContext;
    private List<UserBean> mUserBeanList;

    public UserManagerAdapter(Context context, List<UserBean> userBeanList) {
        mContext = context;
        mUserBeanList = userBeanList;
    }

    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_user_manager,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
        UserBean userBean = mUserBeanList.get(position);
        holder.mTvId.setText(String.valueOf(userBean.getId()));
        holder.mTvName.setText(String.valueOf(userBean.getUsername()));
        holder.mTvPass.setText(String.valueOf(userBean.getPassword()));
    }

    @Override
    public int getItemCount() {
        if (mUserBeanList == null) {
            return 0;
        } else {
            return mUserBeanList.size();
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView mTvId;
        private final TextView mTvName;
        private final TextView mTvPass;

        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            mTvId = itemView.findViewById(R.id.tv_id);
            mTvName = itemView.findViewById(R.id.tv_name);
            mTvPass = itemView.findViewById(R.id.tv_pass);
        }
    }

}
